//
//  MCTableBaseMetadata.m
//  GridGovernance
//
//  Created by 吴欧 on 2018/1/19.
//  Copyright © 2018年 Bitvalue. All rights reserved.
//

#import "MCTableBaseMetadata.h"
#import "MCTableBaseCell.h"

@interface MCTableBaseMetadata ()

@property (nonatomic, weak) MCTableBaseCell *cell;

@end

@implementation MCTableBaseMetadata

- (instancetype)init {
    if (self = [super init]) {
        _fillCellMetaDataBlock = [self defaultFillCellMetaDataBlock];
        _fiterCellModelBlock = [self setupFiterCellModelBlock];
    }
    return self;
}

- (fillCellMetaDataBlock)defaultFillCellMetaDataBlock {
    __weak typeof(self) wkSelf = self;
    return ^(MCTableBaseCell *cell, MCTableBaseMetadata *metaData) {
        __strong typeof(self) sgSelf = wkSelf;
        sgSelf.cell = cell;
        cell.metaData = metaData;
    };
}

- (fiterCellModelBlock)setupFiterCellModelBlock {
    __weak typeof(self) wkSelf = self;
    return ^(MCTableBaseCell *cell, MCTableBaseMetadata *metaData, GDFormModel *formModel, NSIndexPath *indexPath) {
        __strong typeof(self) sgSelf = wkSelf;
        sgSelf.cell = cell;
        cell.metaData = metaData;
        cell.formModel = formModel;
        cell.fiterModel = (GDFiterCellModel *)metaData;
        [cell refreshContent:(GDFiterCellModel *)metaData formModel:formModel indexPath:indexPath];
    };
}

- (CGFloat)cellHeight {
    return [_cell sizeThatFits:CGSizeZero].height;
}

- (void)getCellHeightBlock:(getCellHeight)block {
    _heightBlock = block;
}

@end
